/**
 * 聚合个数/面积
 * 功能: 
 *  图片树的构造 ; 
 *  根据市或区维度/土地类型 来聚合 [生成的聚合图放置于市区的中心点]
 *  
 */
define([
    "dojo/_base/declare",
    "gistech/widgets/normalDialog/NormalDialog",
    "dojo/text!./templates/Template.html",
    "dojo/_base/lang",
    "dojo/topic",
    "dojo/dom-style",
    "dojo/dom-construct",
    "dojo/on",
    "dojo/_base/connect",
    "gistech/util/ajaxUtil",
    "gistech/util/symbolUtil",
    "dojo/dom-style","dojo/query","dojo/dom-class","dojo/topic",
    "esri/layers/FeatureLayer","esri/layers/GraphicsLayer","esri/InfoTemplate",
     "esri/geometry/Polygon","esri/graphic",
    "esri/tasks/QueryTask","esri/tasks/query","gistech/util/mapUtil","esri/geometry/Point",
    "esri/SpatialReference", "gistech/widgets/ClusterInfoWindow/ChartWidget","esri/layers/ArcGISDynamicMapServiceLayer"
    ],
    function(declare,NormalDialog,template,lang,topic,style,domConstruct,on,eventconnect,ajaxUtil,
    		symbolUtil,domStyle,query,domClass,topic
    		,FeatureLayer,GraphicsLayer,InfoTemplate,Polygon,Graphic,QueryTask,ArcQuery,mapUtil,Point,SpatialReference,ChartWidget 
    		,ArcGISDynamicMapServiceLayer
    		){
        return declare([NormalDialog],{
        templateString:template,
        container:null,
        legendWidget:null,
        clusterType:'landCount',
        constructor:function (args) {
        	this.inherited(arguments);
        	this.landTypeItem = (args.landTypeItem  != undefined) ? args.landTypeItem :null;
        	this.map = args.map;
        	this.clusterData=[];//存储选中的土地
        	/**
        	 * 相关全局变量
        	ioc.map.clusterClickName;//点击饼状图时的区域名称
        	ioc.map.cluster;//是否使用了聚合,地图缩放时做判断
        	ioc.map.clusterData;//点击聚合时查询的结果集
        	ioc.map.ClusterMapLevel//聚合后当前地图级别 用于判断是否在同一维度,是否需要重新获取聚合结果集 eg 区维度-->市维度
        	ioc.map.ClusterDimension; //当前维度值: province city distinct
        	ioc.map.clusterselNodeStr 勾选的树节点值
        	ioc.map.clusterType 聚合的类型分:个数/面积 和 项目状态两种,用于区分放大缩小区域时触发的监听[两种类型的聚合都监听了changeCluster这个事件]
        	*/
        },
        postCreate:function(){
            this.inherited(arguments);
            this.init();
            this.addEvents();
        },
        /**
         * 初始化
         */
        init:function () {
        	
        	this.createLandResTree();
        	this.initLandResTreeDiagram();
//        	 this.initCityDistinctData(); //初始化中心点 找出后在 /sddc/src/main/webapp/client/gistech/util/CityDistCenters.js 这里加进去
        },
        
        /**
         * 添加事件
         */
        addEvents:function(){
        	on(this.clusterTreeOk,"click",lang.hitch(this,this._okFun));//搜索
        	//on(this.cleanCLuster,"click",lang.hitch(this,this.cleanCluster));//清除
        	topic.subscribe("changeCluster", lang.hitch(this, this.changeClusterData));//地图区域变动时重新加载
        },
        startup:function(){
            this.inherited(arguments);
        },
        //导出Excel
        exportCLusterData:function(){
        	//格式化选中的节点
        	var formatSelNode=this.formatSelNode();
        	
        	var selNodeStr = this.selNodeData(formatSelNode);
        	
        	if(!selNodeStr){
        		return false;
        	}
			 //后台处理数据
	      	ajaxUtil.request("../client/service/clusterController/exportClusterLandData",
	    		 "clusterParam="+selNodeStr,lang.hitch(this,function(result){
 
	    	    })
	    	 )
        },
        cleanCluster:function(){
        	ioc.map.cluster=false;//清除图层用
        	this.delPie();
        	this.legendWidget.destroy();
        	this.legendWidget=null;
        },
        addPie:function(flag){
	    	  var temp = this;
			  this.initCluster(null,null,flag,temp);
        },
        delPie:function(){
          for(var d=0;d<50;d++){ //TODO 这里删除一次不知为何节点有漏,50为多次删除
        	var canvasNodes = document.getElementsByTagName('canvas');
        	 for(var g=0;g<canvasNodes.length;g++){
        	  var aNode = document.getElementsByTagName('canvas')[g].parentNode;
        		 if(aNode != undefined){
        		  var bNode = aNode.parentNode
        		      if(bNode != undefined){
        			  if(bNode.attributes[0].nodeValue=="stat2"){
        			      //删除
        			       var pNode = document.getElementsByTagName('canvas')[g].parentNode.parentNode.parentNode;
        				for (var i = 0;i<pNode.childNodes.length;i++){
        				    pNode.removeChild(pNode.childNodes[i]);
        				}
        				break;
        			  }
        		      }
        		 }
        	 }}
        },
        //比例尺变动时改变聚合
        changeClusterData:function(){
        	
        	if(!ioc.map.cluster){
        	  return;	
        	}
        	
        	if(ioc.map.clusterType!="countArea"){
        		return;	
        	}
//        	console.log(this.map.getLevel())
        	if(ioc.map.clusterData!=undefined && ioc.map.clusterData!=null)
            if(ioc.map.ClusterMapLevel!=this.map.getLevel()){
            	this.delPie();
            	var mark="";
            	//3级别以下省;4,5,6级别市 ; 7以上行政区
            	if(this.map.getLevel()<=3){
            		mark="province"
            	}else if(this.map.getLevel()>=4 && this.map.getLevel()<=6){
            		mark="city"
            	}else if(this.map.getLevel()>=7){
            		mark="distinct"
            	}
            	ioc.map.ClusterMapLevel = this.map.getLevel() ; 
            	if(mark == ioc.map.ClusterDimension){// 同一个维度时重新加载 
                	this.addPie(0);
            	}else{// 非同一个维度时重新查询加载 
            		  
            		if(mark == 'distinct' ){  
            			ioc.map.ClusterDimension = mark;
                    	this.addPie(1);
                	}else if(mark == 'city'){ 
                		ioc.map.ClusterDimension = mark;
                    	this.addPie(2);
                	}else if(mark == 'province'){ 
                		ioc.map.ClusterDimension = mark;
                    	this.addPie(3);
                	}
            		ioc.map.ClusterDimension = mark;
            	}
            }else{//拖动 不需操作
            }
        },
        getLayer:function(){
        	if(!this._toolTipLayer){
        		this._toolTipLayer=dojo.toDom("<div style='position: absolute;z-index:20;'></div>");
        	}
        	dojo.place(this._toolTipLayer,this.map.root);
        	return this._toolTipLayer;
        },
        _okFun:function(){
        	//格式化选中的节点
        	var formatSelNode=this.formatSelNode();
        	//为土地类型输入框赋值
        	this.toInputItemAssign(formatSelNode);
        	//关闭对话框
//        	this.closeDialog();
        	if(Global.widgets.legendWidget){
        		Global.widgets.legendWidget.resetLegend();
        	}
        },
        clustData:function(flag,selNodeStr){
        	this.delPie();
        	ioc.map.cluster=true;
        	ioc.map.clusterType="countArea";//个数/面积
        	if(ioc.map.shiQufeatures == undefined){
        		ioc.map.shiQufeatures = [];
        	}
//    		var quLayer = new ArcGISDynamicMapServiceLayer("http://10.1.10.230:6080/arcgis/rest/services/SL/0805/MapServer/1", {id:'quLayer'});
//    		this.map.addLayer(quLayer);
    		var temp = this;
    		if(flag !=0){
    			 //后台处理数据
    	      	ajaxUtil.request("../client/service/clusterController/clusterLandData",
    	    		 "clusterParam="+selNodeStr,lang.hitch(this,function(result){
    	    			 var Store = eval(result.result);
    	    			 if(Store!=null && Store.length>0){
    	    				 ioc.map.clusterData=Store; 
    	    				  
    	    					 this.initCluster(null,null,flag,temp);

    	    			 }
    	    	    })
    	    	 )
    		}else{
        		 this.initCluster(null,null,flag);
    		}
        },
        initCluster:function(queryTask,query,flag,temp){
        	  if(queryTask==null){
        		  if(ioc.map.ClusterDimension == 'city'){
        			  this.dealWithData(ioc.map.shifeatures,flag,temp);
        		  }else if(ioc.map.ClusterDimension == 'distinct'){
        			  this.dealWithData(ioc.map.qufeatures,flag,temp);
        		  }
        	  }else{
        		  if(flag==9){
        			  queryTask.execute(query,lang.hitch(this,function(feaset){
        				  ioc.map.shifeatures=feaset;
        			  }));
        		  }else if(flag==10){
        			  queryTask.execute(query,lang.hitch(this,function(feaset){
        				  ioc.map.qufeatures=feaset;
        			  }));
        		  }
        	  }
        },
        dealWithData:function(feaset,flag,temp){
        	if(feaset.length>0){
        		if(Global.widgets.legendWidget==null){
        			require(["gistech/widgets/LegendWidget/LegendWidget"], lang.hitch(this,function (LegendWidget){
        				Global.widgets.legendWidget = new LegendWidget({map:this.map});
        				Global.widgets.legendWidget.placeAt(dojo.body());
        				Global.widgets.legendWidget.startup();
        			}));
        		}
        		for(var i=0;i<feaset.length;i++){
        			var fs = feaset[i];
        			var tPoint = fs.point;
        			var name = fs.name ; 
        			var clusdata = ioc.map.clusterData;
        			if(clusdata.length>0){

        				for(var j=0;j<clusdata.length;j++){
        					var data = clusdata[j];
        					var dimensionName = "";
        					if(flag==1 || ioc.map.ClusterDimension == 'distinct'){
        						dimensionName = data.district
        					}else if(flag==2 || ioc.map.ClusterDimension == 'city'){
        						dimensionName = data.city;
        					}else if(flag==3 || ioc.map.ClusterDimension == 'province' ){ 
        						dimensionName = ""; //TODO 省
        					}
        					if(name== dimensionName ){
        						var isCity = false;
        						if(ioc.map.ClusterDimension=='city' && data.district==undefined){
        							isCity = true ; 
        						}
        						if( ioc.map.ClusterDimension=='city' && !isCity){break;}
        						var chartWidget =  new ChartWidget({map:temp.map,clusterType:this.clusterType});

//      						debugger;
//      						var ltextSymbol = new esri.symbol.TextSymbol({text:name,
//      						font:new esri.symbol.Font("1px"), 
//      						color:new dojo.Color({r:255,g:0,b:0}),
//      						haloColor:new dojo.Color({r:255,g:255,b:255}),
//      						horizontalAlignment:"center",xoffset:-10,yoffset:-3
//      						});
//      						this.map.graphics.add(new esri.Graphic(tPoint,ltextSymbol));


        						chartWidget.placeAt(temp.getLayer()).show(tPoint);
        						if(this.clusterType=='landCount') //个数
        							chartWidget.startup(dimensionName,data.czldCount,data.gyjcydCount,data.sjjcCount,data.sjjtjcCount,data.sjjchCount,data.gysbydCount);
        						else if(this.clusterType=='landArea') //面积
        							chartWidget.startup(dimensionName,data.czldArea,data.gyjcydArea,data.sjjcArea,data.sjjtjcArea,data.sjjchArea,data.gysbydArea);

        						Global.widgets.legendWidget.initLegend(dimensionName,data.czldArea,data.gyjcydArea,data.sjjcArea,data.sjjtjcArea,data.sjjchArea,data.gysbydArea);
        					}
        				}
        			}
        		}
        		Global.widgets.legendWidget.initLayerListHandler();
        	}
        },
        //格式化选中的节点数组
        formatSelNode:function(){
        	var formatSelNode=[];
        	for(var i=0;i<this.selNode.length;i++){
        		for(var j=0; j<this.ableSelNode.length; j++){
            		if(this.selNode[i] == this.ableSelNode[j]["key"]){
            			formatSelNode.push(this.ableSelNode[j]["name"]);
            			break;
            		}
            	}
        	}
        	return  formatSelNode;
        },
        selNodeData:function(formatSelNode){
        	var selNodeStr="0";
        	if(formatSelNode.length != 0){
        		if(formatSelNode.length>1){
            		 selNodeStr=formatSelNode.join(",");
            		 for(var g=0;g<formatSelNode.length;g++){
            			 if(formatSelNode[g]=='纳入三旧的旧厂'){
            				 selNodeStr+=',2';
            			 }else if(formatSelNode[g]=='纳入三旧的旧城'){
            				 selNodeStr+=',3';
            			 }else if(formatSelNode[g]=='国有储备用地'){
            				 selNodeStr+=',4';
            			 }else if(formatSelNode[g]=='纳入三旧的旧村'){
            				 selNodeStr+=',7';
            			 }else if(formatSelNode[g]=='纳入三旧的集体旧厂'){
            				 selNodeStr+=',9';
            			 }else if(formatSelNode[g]=='村自留地'){
            				 selNodeStr+=',10';
            			 } 
            		 }
            	}else{
            		selNodeStr = formatSelNode[0]
            		if(selNodeStr=='纳入三旧的旧厂'){
       				 selNodeStr+=',2';
       			 }else if(selNodeStr=='纳入三旧的旧城'){
    				 selNodeStr+=',3';
    			 }else if(selNodeStr=='国有储备用地'){
    				 selNodeStr+=',4';
    			 }else if(selNodeStr=='纳入三旧的旧村'){
       				 selNodeStr+=',7';
       			 }else if(selNodeStr=='纳入三旧的集体旧厂'){
       				 selNodeStr+=',9';
       			 }else if(selNodeStr=='村自留地'){
       				 selNodeStr+=',10';
       			 } 
            	}
        	}  
        	if(selNodeStr=="0"){
        		alert('请选择筛选条件');
        		return false;
        	}
        	return selNodeStr;
        },
        //为土地类型输入文本框赋值
        toInputItemAssign:function(formatSelNode){
        	var selNodeStr = this.selNodeData(formatSelNode);
        	if(!selNodeStr){
        		return false;
        	}
        	ioc.map.clusterselNodeStr=selNodeStr;
        	if(ioc.map.ClusterMapLevel == null){
        		ioc.map.ClusterMapLevel = this.map.getLevel();
            	//3级别以下省;4,5,6级别市 ; 7以上行政区
            	if(this.map.getLevel()<=3){
            		ioc.map.ClusterDimension="province"
            	}else if(this.map.getLevel()>=4 && this.map.getLevel()<=6){
            		ioc.map.ClusterDimension="city"
            	}else if(this.map.getLevel()>=7){
            		ioc.map.ClusterDimension="distinct"
            	}
        	}
        	if(this.map.getLevel()<=3){
        		mark="province"
        	}else if(this.map.getLevel()>=4 && this.map.getLevel()<=6){
        		mark="city"
        	}else if(this.map.getLevel()>=7){
        		mark="distinct"
        	}
        	ioc.map.ClusterMapLevel = this.map.getLevel() ; 
        	// 非同一个维度时重新查询加载 
        		var flag =null;
        		if(mark == 'distinct' ){//  
        			this.clustData(1,selNodeStr)
            	}else if(mark == 'city'){//  
            		this.clustData(2,selNodeStr)
            	}else if(mark == 'province'){//  
            		this.clustData(3,selNodeStr)
            	}
        },
        
        //初始化土地资源树图表
        initLandResTreeDiagram:function(){
        	var formatSelNode=[];
        	var selNode=[];
        	if(this.landTypeItem!=null && this.landTypeItem.val()!=""){
        		if(this.landTypeItem.val().indexOf("...")!=-1){
        			if(this.landTypeItem[0].title.replace(/\s/g,"").indexOf(",")!=-1){
        				selNode=this.landTypeItem[0].title.replace(/\s/g,"").split(",");
        			}else{
        				selNode.push(this.landTypeItem[0].title.replace(/\s/g,""));
        			}
        		}else{
        			if(this.landTypeItem.val().replace(/\s/g,"").indexOf(",")!=-1){
        				selNode=this.landTypeItem.val().replace(/\s/g,"").split(",");
        			}else{
        				selNode.push(this.landTypeItem.val().replace(/\s/g,""));
        			}
        		}
        		if(selNode.length != 0){
        			for(var i=0;i<selNode.length;i++){
                		for(var j=0; j<this.ableSelNode.length; j++){
                    		if(selNode[i] == this.ableSelNode[j]["name"]){
                    		    this.myDiagram.findNodeForKey(this.ableSelNode[j]["key"]).isSelected=true;
                    			formatSelNode.push(this.ableSelNode[j]["key"]);
                    			break;
                    		}
                    	}
                	}
        		}
        	}
        	this.selNode=formatSelNode;
        },
        closeDialog:function(){
			this.inherited("closeDialog",arguments);
			this.destroy();
		},
        /**
         * 关闭对话框
         */
        closeDialog:function(){
			this.inherited("closeDialog",arguments);
			this.destroy();
		},
        /**
         * 创建土地资源树
         */
        createLandResTree:function(){
        	 if (window.goSamples) goSamples();  // init for these samples -- you don't need to call this
             var $ = go.GraphObject.make;  // for conciseness in defining templates
             this.myDiagram =
                $(go.Diagram, "clusterTreeDiagramDiv",  // must be the ID or reference to div
                 {
                 "toolManager.hoverDelay": 100,  // 100 milliseconds instead of the default 850
                 allowCopy: false, allowSelect: true,allowMove:false,allowResize:false,allowReshape:false,allowMove:false,allowRelink:false,allowDragOut:false,allowHorizontalScroll:false,
                 click:function(){
//                	 
                     if(this.selNode.length != 0){
                         for(var i=0;i<this.selNode.length;i++){
                             if(!this.myDiagram.findNodeForKey(this.selNode[i]).isSelected){
                                 this.myDiagram.findNodeForKey(this.selNode[i]).isSelected=true;
                             }
                         }
                     }
                 }.bind(this),
                 LayoutCompleted:function(){
                     this.myDiagram.zoomToFit();
                 }.bind(this),
                 layout:  // create a TreeLayout for the family tree
                   $(go.TreeLayout,{ angle: 0, nodeSpacing: 10, layerSpacing: 40, layerStyle: go.TreeLayout.LayerUniform })
             });
             var graygrad = 'Silver';
             var pinkgrad = '#FFCCCC';
             var noStroke = null;
             var strokeStyle1='#5CACEE';
             var strokeStyle2='#FF6600';
             //var selNode=[];
             // define Converters to be used for Bindings
             function genderBrushConverter(fillCol) {
                 if (fillCol === "noSel") return graygrad;
                 if (fillCol === "sel") return pinkgrad;
                 return "white";
             }
             function dsySetStroke(fillCol) {
                 if (fillCol === "noSel") return noStroke;
                 if (fillCol === "sel") return strokeStyle2;
                 return strokeStyle1;
             }
             // replace the default Node template in the nodeTemplateMapvar selNode=[];
             this.myDiagram.nodeTemplate =
             $(go.Node, "Auto",
                { click: function(e,obj){
                    if(obj.je.fillCol == "sel"){
                            if(this.selNode.length != 0){
                                var isExist=false;
                                for(var i=0;i<this.selNode.length;i++){
                                    if(this.selNode[i] == obj.je.key){
                                        isExist=true;
                                        obj.isSelected=false;
                                        this.selNode.remove(obj.je.key);
                                    }else{
                                        if(!this.myDiagram.findNodeForKey(this.selNode[i]).isSelected){
                                            this.myDiagram.findNodeForKey(this.selNode[i]).isSelected=true;
                                        }
                                    }
                                }
                                if(!isExist){
                                    this.selNode.push(obj.je.key);
                                }
                            }else{
                                this.selNode.push(obj.je.key);
                            }
                    }else{
                        obj.isSelected=false;
                        if(this.selNode.length != 0){
                            for(var i=0;i<this.selNode.length;i++){
                                if(!this.myDiagram.findNodeForKey(this.selNode[i]).isSelected){
                                    this.myDiagram.findNodeForKey(this.selNode[i]).isSelected=true;
                                }
                            }
                        }
                    }
                  }.bind(this)
                },
               { deletable: false/*,toolTip: tooltiptemplate */},
               new go.Binding("text", "name"),
               $(go.Shape, "RoundedRectangle",
                 { fill: "lightgray",
                   stroke: '#5CACEE', strokeWidth: 1.5,cursor:'pointer',width:200,
                   stretch: go.GraphObject.Fill,
                   alignment: go.Spot.Center},
                   new go.Binding("fill", "fillCol", genderBrushConverter),new go.Binding("stroke", "fillCol", dsySetStroke)),

               $(go.TextBlock,
                 { font: "300 17px 微软雅黑",
                   textAlign: "center",
                   margin: 10, maxSize: new go.Size(120, NaN) },
                 new go.Binding("text", "name"))
             );
           // define the Link template
           this.myDiagram.linkTemplate =
             $(go.Link,  // the whole link panel
               { routing: go.Link.Orthogonal, corner: 5, selectable: false,resegmentable:false},
               $(go.Shape, { strokeWidth: 1, stroke: '#424242'}));  // the gray link shape
           // here's the family data
           var nodeDataArray = [
            { key: 0, name: "建设用地", fillCol:"general",setHeight:"sinRowHeight"},
            /*   { key: 1, parent: 0, name: "建设用地", fillCol:"general",setHeight:"sinRowHeight"},*/
                  /* { key: 11, parent: 1, name: "现状建设用地（有规模、有指标）",fillCol:"general"},*/
                       { key: 111, parent: 0, name: "国有建设用地",fillCol:"general",setHeight:"sinRowHeight"},
                           { key: 1111, parent: 111, name: "建成区",fillCol:"general",setHeight:"sinRowHeight"},
                               { key: 11111, parent: 1111, name: "非三旧建成区", fillCol: "noSel",setHeight:"sinRowHeight"},
                               { key: 11112, parent: 1111, name: "纳入三旧的旧厂", fillCol: "sel",existData:true,setHeight:"sinRowHeight"},
                               { key: 11113, parent: 1111, name: "纳入三旧的旧城", fillCol: "sel",existData:true,setHeight:"sinRowHeight"},
                           { key: 1112, parent: 111, name: "未建区",fillCol:"general",setHeight:"sinRowHeight"},
                               { key: 11121, parent: 1112, name: "国有储备用地", fillCol: "sel",existData:true,setHeight:"sinRowHeight"},
                               { key: 11122, parent: 1112, name: "已供未建地", fillCol: "noSel",setHeight:"sinRowHeight"},

                       { key: 112, parent: 0, name: "集体建设用地",fillCol:"general",setHeight:"sinRowHeight"},
                           { key: 1121, parent: 112, name: "建成区",fillCol:"general",setHeight:"sinRowHeight"},
                               { key: 11211, parent: 1121, name: "未纳入三旧的村", fillCol: "noSel",setHeight:"sinRowHeight"},
                               { key: 11212, parent: 1121, name: "纳入三旧的旧村", fillCol: "sel",existData:true,setHeight:"sinRowHeight"},
                               { key: 11213, parent: 1121, name: "未纳入三旧集体物业（工业、商业、仓储等）", fillCol: "noSel"},
                               { key: 11214, parent: 1121, name: "纳入三旧的集体旧厂", fillCol: "sel",existData:true},
                           { key: 1122, parent: 112, name: "未建区",fillCol:"general",setHeight:"sinRowHeight"},
                               { key: 11221, parent: 1122, name: "村自留地", fillCol: "sel",existData:true,setHeight:"sinRowHeight"},
                      { key: 113, parent: 0, name: "待征转用地（有规模、无指标）",fillCol:"general"},
                          { key: 1131, parent: 113, name: "违法建设用地", fillCol: "noSel",setHeight:"sinRowHeight"},
                          { key: 1132, parent: 113, name: "其他可征转用地", fillCol: "noSel",setHeight:"sinRowHeight"},

               /*{ key: 2, parent: 0, name: "非建设用地",fillCol:"general",setHeight:"sinRowHeight"},
                 { key: 21, parent: 2, name: "耕地、林地、园地、草地、其他农用地",fillCol:"general"},
                 { key: 22, parent: 2, name: "未利用地",fillCol:"general",setHeight:"sinRowHeight"},
                 { key: 23, parent: 2, name: "违法建设用地",fillCol:"general",setHeight:"sinRowHeight"}*/
	          ];
           this.ableSelNode=[
                 { key: 11112, parent: 1111, name: "纳入三旧的旧厂", fillCol: "sel",setHeight:"sinRowHeight"},
                 { key: 11113, parent: 1111, name: "纳入三旧的旧城", fillCol: "sel",setHeight:"sinRowHeight"},
                 { key: 11121, parent: 1112, name: "国有储备用地", fillCol: "sel",setHeight:"sinRowHeight"},
                 { key: 11212, parent: 1121, name: "纳入三旧的旧村", fillCol: "sel",setHeight:"sinRowHeight"},
                 { key: 11213, parent: 1121, name: "未纳入三旧集体物业（工业、商业、仓储等）", fillCol: "sel"},
                 { key: 11214, parent: 1121, name: "纳入三旧的集体旧厂", fillCol: "sel",setHeight:"sinRowHeight"},
                 { key: 11221, parent: 1122, name: "村自留地", fillCol: "sel",setHeight:"sinRowHeight"},
            ];
           // create the model for the family tree
           this.myDiagram.model = new go.TreeModel(nodeDataArray);
           
           var divElm = query('#clusterTreeDiagramDiv > div',this.domNode)[0];
           var canvas= query('#clusterTreeDiagramDiv > canvas',this.domNode)[0];
           domStyle.set(divElm, "overflow", "");
           domStyle.set(canvas, "outline", "0");
        },
        //初始化城市区中心点
        initCityDistinctData:function(){
        	var queryTask=null;
        	var urls = [
        	            //"http://map.geoq.cn/ArcGIS/rest/services/ChinaCities_Community_BaseMap_CHN/ChengDu_Community_BaseMap_CHN/MapServer/0",
        	            "http://10.1.10.230:6080/arcgis/rest/services/SLdata/CX2016new/MapServer/3"
        	           ];
//        	var urls = ["http://10.1.10.230:6080/arcgis/rest/services/SLdata/CX2016/MapServer/2",
//        	    		"http://10.1.10.230:6080/arcgis/rest/services/SLdata/CX2016/MapServer/3"];
        	for(var i = 0 ; i<urls.length;i++){
	      		queryTask=new QueryTask(urls[i]);
	        	var query=new ArcQuery();
				query.returnGeometry=true;
				query.outFields=["*"];
				query.where="1=1";
			    var temp = this;
			    queryTask.execute(query,lang.hitch(this,function(feaset){
			    	var c = feaset.features["0"].geometry.getCentroid();
			    	for(var i=0;i<feaset.features.length;i++){
	        			var fs = feaset.features[i];
	        				var p = fs.geometry.getCentroid();
	        				var d = fs.attributes.FQMC
	        				var c = fs.attributes.CSMC;
	        				console.log(c+d+':'+p.x+' '+p.y)
			    	}
			    }));
			    
				if(ioc.map.shifeatures == undefined || ioc.map.qufeatures  == undefined ){
					if(i==0){//市
						this.initCluster(queryTask,query,9,temp);
					}else if(i==1){//区
						this.initCluster(queryTask,query,10,temp);
					}
					
				}
	    	  }
        },
        
     });
});

